package com.dating.base.dao;

import java.util.List;

import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.IocBean;

import com.dating.base.bean.Permission;
import com.dating.base.bean.User;
import com.dating.base.bean.UserPermission;
import com.dating.core.ext.BaseDao;

@IocBean
public class UserPermissionDao extends BaseDao<UserPermission> {

	@Override
	public Class<UserPermission> initClass() {

		return UserPermission.class;
	}
	
	
	/**
	 * 根据用户信息获取权限信息
	 * @param userPer
	 * @return
	 */
	public List<Permission> getPermissions(User user){
		String sql = " select  b.* from t_user_permission a INNER JOIN t_permission b on a.p_id = b.id "
				+ " where a.u_id = @uid and a.u_type = @utype  ";
		Sql sqls = Sqls.queryEntity(sql);
		sqls.setEntity(dao.getEntity(Permission.class));
		sqls.params().set("uid", user.getId());
		sqls.params().set("utype", user.getUserType().name());
		dao.execute(sqls);
		return sqls.getList(Permission.class);
	}
}
